erlang design of a card game [closed]

Posted by user601836 on Stack Overflow See other posts from Stack Overflow or by user601836
Published on 2011-08-22T12:07:26Z Indexed on 2012/10/08 3:37 UTC
Read the original article Hit count: 276

Filed under:
|

I would like to discuss with you a possible implementation for a card game in erlang. The only full example I found online is OpenPoker.

I would like to create one myself, so here is the implementation I have in mind:

  1. A gen_server to represent a deck: when started creates a deck of cards (shuffled). And stores it in its state. provides an handle_call (draw_card)

  2. A gen_server to represent the chat room. Stores in its state the registered name of a player process (e.g. player1, player2, luke etc etc). Exports handle_cast to join the chat (executed by default when somebody joins successfully the game) and one to broadcast a chat message to all users by calling an handle_cast on the gen_server representing a player.

  3. a gen_fsm to represent a game instance. Has two states (wait_join, and turn). Exports join/1 to join the game, play_card/2 and send_msg/2. One parameter is the pid of the player process.

  4. a gen_server to represent the player. Exports only start_link/1 where the parameter is the name to use to register the process (inside the init I call join method of gen_fsm). Has different handle_calls (e.g. get_hand, draw_card) and handle_casts (e.g. play_card, deliver_msg, and send_msg)

  5. A gen_server to represent the main process. Exports (join_game/1 which calls player:start_link/1, send_msg/2 to call player's send_msg, play_card/3 to call player's play_card).

What do you think of this architecture?

Thanks in advance

© Stack Overflow or respective owner

Related posts about erlang

Related posts about playing-cards